home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / largef1a / frmmain.frm < prev   
Text File  |  1999-09-19  |  15KB  |  432 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
  4. Begin VB.Form frmMain 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "File Splitter"
  7.    ClientHeight    =   3315
  8.    ClientLeft      =   45
  9.    ClientTop       =   330
  10.    ClientWidth     =   3765
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   3315
  15.    ScaleWidth      =   3765
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.ComboBox cmbSplitSize 
  18.       Height          =   315
  19.       Left            =   120
  20.       Style           =   2  'Dropdown List
  21.       TabIndex        =   10
  22.       Top             =   960
  23.       Width           =   1335
  24.    End
  25.    Begin VB.Frame fraStats 
  26.       Caption         =   "Statistics"
  27.       Height          =   1335
  28.       Left            =   120
  29.       TabIndex        =   6
  30.       Top             =   1800
  31.       Width           =   3495
  32.       Begin VB.Label lblFileCount 
  33.          AutoSize        =   -1  'True
  34.          Caption         =   "File Count:"
  35.          Height          =   195
  36.          Left            =   120
  37.          TabIndex        =   12
  38.          Top             =   240
  39.          Width           =   750
  40.       End
  41.       Begin VB.Label lblElapsed 
  42.          AutoSize        =   -1  'True
  43.          Caption         =   "Elapsed Time:"
  44.          Height          =   195
  45.          Left            =   120
  46.          TabIndex        =   9
  47.          Top             =   960
  48.          Width           =   1005
  49.       End
  50.       Begin VB.Label lblFinish 
  51.          AutoSize        =   -1  'True
  52.          Caption         =   "Finish Time:"
  53.          Height          =   195
  54.          Left            =   120
  55.          TabIndex        =   8
  56.          Top             =   720
  57.          Width           =   840
  58.       End
  59.       Begin VB.Label lblStart 
  60.          AutoSize        =   -1  'True
  61.          Caption         =   "Start Time:"
  62.          Height          =   195
  63.          Left            =   120
  64.          TabIndex        =   7
  65.          Top             =   480
  66.          Width           =   765
  67.       End
  68.    End
  69.    Begin VB.CommandButton cmdBrowse 
  70.       Caption         =   "..."
  71.       Height          =   255
  72.       Left            =   3360
  73.       TabIndex        =   4
  74.       Top             =   360
  75.       Width           =   255
  76.    End
  77.    Begin VB.TextBox txtFileName 
  78.       Height          =   285
  79.       Left            =   120
  80.       TabIndex        =   3
  81.       Top             =   360
  82.       Width           =   3135
  83.    End
  84.    Begin VB.CommandButton cmdJoin 
  85.       Caption         =   "Join File"
  86.       Enabled         =   0   'False
  87.       Height          =   375
  88.       Left            =   2640
  89.       TabIndex        =   2
  90.       Top             =   960
  91.       Width           =   975
  92.    End
  93.    Begin MSComctlLib.ProgressBar ProgressBar1 
  94.       Height          =   255
  95.       Left            =   120
  96.       TabIndex        =   1
  97.       Top             =   1440
  98.       Width           =   3495
  99.       _ExtentX        =   6165
  100.       _ExtentY        =   450
  101.       _Version        =   393216
  102.       Appearance      =   1
  103.       Scrolling       =   1
  104.    End
  105.    Begin VB.CommandButton cmdSplit 
  106.       Caption         =   "Split File"
  107.       Default         =   -1  'True
  108.       Enabled         =   0   'False
  109.       Height          =   375
  110.       Left            =   1560
  111.       TabIndex        =   0
  112.       Top             =   960
  113.       Width           =   975
  114.    End
  115.    Begin MSComDlg.CommonDialog CommonDialog1 
  116.       Left            =   3120
  117.       Top             =   120
  118.       _ExtentX        =   847
  119.       _ExtentY        =   847
  120.       _Version        =   393216
  121.    End
  122.    Begin VB.Label lblSplitSize 
  123.       AutoSize        =   -1  'True
  124.       Caption         =   "Split Size (KB)"
  125.       Height          =   195
  126.       Left            =   120
  127.       TabIndex        =   11
  128.       Top             =   720
  129.       Width           =   990
  130.    End
  131.    Begin VB.Label lblFileName 
  132.       AutoSize        =   -1  'True
  133.       Caption         =   "Filename:"
  134.       Height          =   195
  135.       Left            =   120
  136.       TabIndex        =   5
  137.       Top             =   120
  138.       Width           =   675
  139.    End
  140. End
  141. Attribute VB_Name = "frmMain"
  142. Attribute VB_GlobalNameSpace = False
  143. Attribute VB_Creatable = False
  144. Attribute VB_PredeclaredId = True
  145. Attribute VB_Exposed = False
  146. Option Explicit
  147. Public Function SplitFiles(ByVal inputFilename As String, newFileSizeBytes As Long) As Boolean
  148. Dim fReadHandle As Long
  149. Dim fWriteHandle As Long
  150. Dim fSuccess As Long
  151. Dim lBytesWritten As Long
  152. Dim lBytesRead As Long
  153. Dim ReadBuffer() As Byte
  154. Dim TotalCount As Long
  155. Dim StartTime As Date
  156. Dim FinishTime As Date
  157. Dim StartTimeDouble As Double
  158. Dim FinishTimeDouble As Double
  159. Dim Count As Integer
  160.     
  161.     ' User Interface Stuff
  162.     StartTime = Now
  163.     StartTimeDouble = getTime
  164.     Me.MousePointer = vbHourglass
  165.     cmdJoin.Enabled = False
  166.     cmdSplit.Enabled = False
  167.     lblStart = "Start Time: " & StartTime
  168.     ProgressBar1.Max = FileLen(inputFilename)
  169.     ProgressBar1.Value = 0
  170.     
  171.     Count = 1
  172.     ' Resize Byte Array for Read
  173.     ReDim ReadBuffer(0 To newFileSizeBytes)
  174.         
  175.     ' Determine Total Number of Output Files for User Interface Only
  176.     TotalCount = (FileLen(inputFilename) \ UBound(ReadBuffer)) + 1
  177.     
  178.     ' Open Read File Handle
  179.     fReadHandle = CreateFile(inputFilename, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
  180.     
  181.     ' If Successful read, continue
  182.     If fReadHandle <> INVALID_HANDLE_VALUE Then
  183.         ' Read First File Block
  184.         fSuccess = ReadFile(fReadHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesRead, 0)
  185.         
  186.         ' Increment ProgressBar
  187.         ProgressBar1.Value = ProgressBar1.Value + lBytesRead
  188.         ProgressBar1.Refresh
  189.         
  190.         ' Loop while not EOF
  191.         Do While lBytesRead > 0
  192.             ' Update File Count Statistic on User Interface
  193.             lblFileCount.Caption = "Split Count: " & Count & " of " & TotalCount
  194.             lblFileCount.Refresh
  195.             
  196.             ' Open Write File Handle
  197.             If Dir(inputFilename & "." & Count) <> "" Then
  198.                 Kill inputFilename & "." & Count
  199.             End If
  200.             fWriteHandle = CreateFile(inputFilename & "." & Count, GENERIC_WRITE Or GENERIC_READ, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
  201.             ' If Successful Write, Continue
  202.             If fWriteHandle <> INVALID_HANDLE_VALUE Then
  203.                 ' Write Data Block to File
  204.                 fSuccess = WriteFile(fWriteHandle, ReadBuffer(0), lBytesRead, lBytesWritten, 0)
  205.                 If fSuccess <> 0 Then
  206.                     ' Required to Write to File
  207.                     fSuccess = FlushFileBuffers(fWriteHandle)
  208.                     ' Close Write File
  209.                     fSuccess = CloseHandle(fWriteHandle)
  210.                 Else
  211.                     ' On Failure Quit
  212.                     lblFileCount.Caption = "Split Count: Write Error"
  213.                     SplitFiles = False
  214.                     Exit Function
  215.                 End If
  216.             Else
  217.                 ' On Failure Quit
  218.                 lblFileCount.Caption = "Split Count: Write Error"
  219.                 SplitFiles = False
  220.                 Exit Function
  221.             End If
  222.             ' Get the next Read Block
  223.             fSuccess = ReadFile(fReadHandle, ReadBuffer(0), UBound(ReadBuffer), lBytesRead, 0)
  224.                        
  225.             ' Increment ProgressBar
  226.             ProgressBar1.Value = ProgressBar1.Value + lBytesRead
  227.             ProgressBar1.Refresh
  228.             
  229.             ' Increment Count
  230.             Count = Count + 1
  231.         Loop
  232.         ' Close Read File
  233.         fSuccess = CloseHandle(fReadHandle)
  234.     Else
  235.         ' On Failure Quit
  236.         lblFileCount.Caption = "Split Count: Read Error"
  237.         SplitFiles = False
  238.         Exit Function
  239.     End If
  240.     
  241.     ' User Interface Stuff